<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>
        while(true)
    {        let randomNum = Math.floor(Math.random() * 10 + 1)
        let num = prompt('猜猜我随机生成了什么数字(1-10)，你猜的数字是:')
        let isGuess = guessNumberGame(+num,randomNum)
        if (isGuess) {
            alert('恭喜你猜对了')
            break
        }
        else {
            alert('猜错了再接再厉,本次生成的数字是'+randomNum)
        }}

        // document.write(guessNumberGame())
        function guessNumberGame(num, randomNum) {
            if (num == null || typeof num !== Number) {
                return false
            }
            console.log(randomNum);
            if (+num == randomNum) {
                return true
            }
            else {
                return false
            }
        }
    </script>
</body>

</html>